﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.IRepository.SystemSettings.QualificationAdministration;
using SystemCenterSoa.PoModel.SystemSettings.QualificationAdministration;
using SystemCenterSoa.Repository.CommonLib;

namespace SystemCenterSoa.Repository.SystemSettings.QualificationAdministration
{
    public class ArcTitltSettingRepository : BaseRepository, IArcTitltSettingRepository
    {
        public ArcTitltSettingRepository(SystemCenterDbSoaContext systemCenterDbSoaContext) : base(systemCenterDbSoaContext)
        {

        }
        public bool ArcTitltSettingAdd(ArcTitltSettingPo info)
        {
            _systemCenterDbSoaContext.ArcTitltSettingPo.Add(info);
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }

        public bool ArcTitltSettingDelete(string ids)
        {
            string[] arr = ids.Split(',');
            foreach (var item in arr)
            {
                var id = Convert.ToInt32(item);
                var list = _systemCenterDbSoaContext.ArcTitltSettingPo.Find(id);
                _systemCenterDbSoaContext.ArcTitltSettingPo.Remove(list);
            }
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }

        public ArcTitltSettingPo ArcTitltSettingEdit(int id)
        {
            return _systemCenterDbSoaContext.ArcTitltSettingPo.FirstOrDefault(p => p.arc_title_set_id == id);
        }

        public bool ArcTitltSettingUpdate(ArcTitltSettingPo info)
        {
            _systemCenterDbSoaContext.Entry(info).State = EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }

        public PagerResult<ArcTitltSettingPo> SearchPage(SearchModel searchModel)
        {
            var query = _systemCenterDbSoaContext.ArcTitltSettingPo.AsQueryable();
            //判断有没有搜索条件
            if (searchModel.SearchItem != null && searchModel.SearchItem.Count > 0)
            {
                //把搜索条件拿出来
                var tempDi = searchModel.SearchItem;

                //搜索字段为role_name
                string name = "name";
                //判断搜索条件中是否有role_name
                if (tempDi.Keys.Contains(name) && !string.IsNullOrEmpty(tempDi[name]))
                {
                    query = query.Where(c => c.arc_title_set_name.Contains(tempDi[name]));
                }

            }
            return BasePageSearch(query, searchModel);
        }
    }
}
